package com.zjj.edu.web.controller.system;

import com.zjj.edu.common.core.controller.BaseController;
import com.zjj.edu.common.core.page.TableDataInfo;
import com.zjj.edu.common.utils.StringUtils;
import com.zjj.edu.framework.util.ShiroUtils;
import com.zjj.edu.system.domain.SysCampus;
import com.zjj.edu.system.domain.SysClass;
import com.zjj.edu.system.domain.SysCourse;
import com.zjj.edu.system.domain.SysTeachGoods;
import com.zjj.edu.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 通用Controller
 *
 * @author zjj
 * @date 2020-06-02
 */
@Controller
@RequestMapping("/system/common")
public class SysCommonController extends BaseController
{
    private String prefix = "system/common";

    @Autowired
    private ISysCampusService sysCampusService;

    @Autowired
    private ISysTeachGoodsService teachGoodsService;

    @Autowired
    private ISysCourseService courseService;

    @Autowired
    private ISysTenantService tenantService;

    @Autowired
    private ISysClassService sysClassService;

    /**
     * 查询租户校区列表
     */
    @PostMapping("/tenantCampus")
    @ResponseBody
    public TableDataInfo tenantCampusList(SysCampus sysCampus)
    {
        sysCampus.setTenantId(ShiroUtils.getTenantId());
        List<SysCampus> list = sysCampusService.selectSysCampusList(sysCampus);
        return getDataTable(list);
    }

    /**
     * 查询租户教学物品列表
     */
//    @RequiresPermissions("system:common:tenantGoods")
    @PostMapping("/tenantGoods")
    @ResponseBody
    public TableDataInfo tenantGoodsList(SysTeachGoods goods)
    {
        goods.setTenantId(ShiroUtils.getTenantId());
        goods.setStatus("0");
        List<SysTeachGoods> list = teachGoodsService.selectSysTeachGoodsList(goods);
        return getDataTable(list);
    }

    @PostMapping("/tenantCourse")
    @ResponseBody
    public TableDataInfo tenantCourseList(SysCourse course)
    {
        course.setTenantId(ShiroUtils.getTenantId());
        course.setStatus("0");
        List<SysCourse> list = courseService.selectSysCourseList(course);
        return getDataTable(list);
    }

    @PostMapping("/searchClass")
    @ResponseBody
    public TableDataInfo searchClassList(SysClass sysClass)
    {
        sysClass.setTenantId(ShiroUtils.getTenantId());
        sysClass.setStatus("0");
        String tempIds = sysClass.getTempIds();
        if (StringUtils.isNotEmpty(tempIds)) {
            sysClass.setIds(tempIds.split(","));
        }
        List<SysClass> list = sysClassService.selectSysClassList(sysClass);
        return getDataTable(list);
    }



}
